package top.frsf.pattern.b_structural.b_proxy.b_jdk;

import java.lang.reflect.Proxy;

/**
 * JDK动态代理工厂类
 *
 * @author He Kuntao 
 * @since  2025/5/13 9:39
 */
public class DynamicProxyFactory {

    /**
     * 获取代理对象
     *
     * @param clazz 被代理类
     * @return 代理对象
     */
    public static Object getProxy(Class<?> clazz) throws InstantiationException, IllegalAccessException {
        Object instance = clazz.newInstance();
        DynamicProxy dynamicProxy = new DynamicProxy();
        dynamicProxy.setTarget(instance);

        return Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), dynamicProxy);
    }
}
